﻿using EzDesk.Modularity;
using EzDesk.DesktopClient.Event;
using System.Windows;
using EzDesk.Generic;
using Microsoft.Practices.Unity;

namespace EzDesk.DesktopClient.MessageModule
{
    public class MessageModuleInfo : IModule
    {
        private Window _messageViewWindow;

        public Window MessageViewWindow
        {
            get
            {
                if (null == _messageViewWindow)
                {
                    _messageViewWindow = new MessageWindowViewModel().View as Window;
                }
                return _messageViewWindow;
            }
        }

        public IModule Initialize()
        {

            IMClientUnityContainer.Instance.RegisterType<IFeedItemView, FeedItemView>();
            IMClientUnityContainer.Instance.RegisterType<IFeedView, FeedView>();
            IMClientUnityContainer.Instance.RegisterType<IMessageWindowView, MessageWindowView>();

            LoginEvent.Instance.Subscribe(this.OnUserLogin);
            LogoutEvent.Instance.Subscribe(this.OnUserLogout);

            return this;
        }
        protected void OnUserLogin(LoginArgs args)
        {
            args.IsSuccess.TrueDo(this.MessageViewWindow.Show);
        }
        protected void OnUserLogout(LogoutArgs args)
        {
            this.MessageViewWindow.Hide();
        }

    }
}
